import 'package:flutter/material.dart';
import 'package:xvideos/assets_tool/app_colors.dart';
import 'package:xvideos/assets_tool/images.dart';

class CErrorWidget extends StatefulWidget {
  final String? errorMsg;
  final String? errorMsg2;
  final VoidCallback? retryOnTap;

  const CErrorWidget({super.key, this.errorMsg = "什么也没有...", this.errorMsg2, this.retryOnTap});

  @override
  State<StatefulWidget> createState() {
    return CErrorWidgetState();
  }
}

class CErrorWidgetState extends State<CErrorWidget> {
  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (_, cons) {
      if (cons.maxHeight < 146) return SizedBox.shrink();
      return Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Image.asset(
                "ic_nodata.webp".commonImgPath,
                height: 120,
              ),
              Text(
                widget.errorMsg ?? "",
                style: TextStyle(color: Colors.white.withOpacity(0.6), fontSize: 12),
              ),
              Visibility(
                visible: widget.retryOnTap != null,
                child: InkWell(
                  onTap: widget.retryOnTap,
                  child: Container(
                    padding: const EdgeInsets.fromLTRB(12, 8, 12, 12),
                    child: Text(
                      "点击重试",
                      style: TextStyle(
                        color: Color(0xff3E64EA).withOpacity(0.8),
                        fontSize: 12,
                      ),
                    ),
                  ),
                ),
              )
            ],
          )
        ],
      );
    });
  }
}
